

#pragma once

#include <string>
#include <memory>
#include <vector>
#include <map>

extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavfilter/avfilter.h>
#include <libavutil/buffer.h>
#include <libavutil/buffer.h>
#include <libavutil/hwcontext.h>

}

class HwInstance
{
    struct AVBufferRefData
    {
        AVHWDeviceType m_hw_type{AV_HWDEVICE_TYPE_NONE};
        int            m_index{0};
        AVBufferRef *  m_buffer_ref{nullptr};
        ~AVBufferRefData();
    };
public:
	static HwInstance * Instance()
	{
		static HwInstance instance;
		return &instance;
	}
public:
	~HwInstance();
	AVBufferRef * GetBuffer(const std::string & name = "");
    AVBufferRef * GetBuffer(AVHWDeviceType hw_type);
    AVHWDeviceType GetHwType(const std::string & name);
	void AddBuffer(AVBufferRef * buffer);
private:
private:
	HwInstance();
	bool CreateHw(const std::string & hw_name);
private:
	std::map<std::string,std::shared_ptr<AVBufferRefData>> m_buffer_map;
};